<%@ page language="java" contentType="application/vnd.ms-excel; charset=UTF-8" %>
<%@ page import="weaver.hrm.report.schedulediff.HrmScheduleDiffManager"%>
<%@ page import="weaver.systeminfo.*,java.util.*,weaver.hrm.*" %>
<%@ page import="weaver.general.Util,weaver.hrm.common.*" %>
<%@ page import="weaver.hrm.attendance.domain.*"%>
<!-- modified by wcd 2014-07-24 [E7 to E8] -->
<jsp:useBean id="colorManager" class="weaver.hrm.attendance.manager.HrmLeaveTypeColorManager" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="strUtil" class="weaver.common.StringUtil" scope="page"/>
<jsp:useBean id="dateUtil" class="weaver.common.DateUtil" scope="page"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	User user = HrmUserVarify.getUser (request , response) ;
	if(user == null)  return ;
	response.setContentType("application/vnd.ms-excel");
	
	Calendar today = Calendar.getInstance ();
	String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
					   + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
					   + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);//当前时间

	String cmd = strUtil.vString(request.getParameter("cmd"));//用于区分
	String fromDate = strUtil.vString(request.getParameter("fromDate"));//开始时间
	String toDate = strUtil.vString(request.getParameter("toDate"));//结束时间
	
	
	String XMNo = Util.null2String(request.getParameter("XMNo"));//项目编号
	
	String tnum = strUtil.vString(request.getParameter("tnum"));
	String subCompanyId = strUtil.vString(request.getParameter("subCompanyId"));//分部id
	String departmentId = strUtil.vString(request.getParameter("departmentId"));//部门id
	String resourceId = strUtil.vString(request.getParameter("resourceId"));//人员id
	String status = strUtil.vString(request.getParameter("status"));//状态id
	//非考勤管理员只能看到自己的记录
	if(!HrmUserVarify.checkUserRight("BohaiInsuranceScheduleReport:View", user)){
		resourceId = String.valueOf(user.getUID());
	}
	String fileName = "手续部报表";
	response.setHeader("Content-disposition","attachment;filename="+new String(fileName.getBytes("GBK"),"iso8859-1")+".xls");
%>
<%
	if(cmd.equals("CheckWorkAttendance")){
%>
<table  border=1  bordercolor=black style="border-collapse:collapse;" width="100%" >
	<tbody>
		<tr><td align="center" colspan="27"><%=fileName%></td></tr>
		<tr>
			<td align="center" rowspan="3" colspan="4">项目基本信息</td>
			<td align="center" colspan="15">手续内容</td>
			<td align="center" colspan="8">竣工资料上传</td>
			<!--<td align="center" rowspan="3">其他</td>-->
		</tr>
		<tr>
			<td align="center" colspan="5">消防</td>
			<td align="center" colspan="6">环保</td>
			<td align="center" colspan="3">招牌</td>
			<td align="center">卫生</td>
			<td align="center" rowspan="2" colspan="4">消防</td>
			<td align="center" rowspan="2">卫生</td>
			<td align="center" rowspan="2" colspan="2">环保</td>
			<td align="center" rowspan="2">招牌</td>
		</tr>
		<tr>
			<td align="center" colspan="2">项目费用信息</td>
			<td align="center" colspan="3">内容</td>
			<td align="center" colspan="2">项目费用信息</td>
			<td align="center" colspan="4">内容</td>
			<td align="center" colspan="2">项目费用信息</td>
			<td align="center">内容</td>
			<td align="center">内容</td>
		</tr>
		
		<tr>
			<td align="center">序号</td>
			<td align="center">项目编号</td>
			<td align="center">项目名称</td>
			<td align="center">项目区域</td>
			
			<td align="center">分包单位名称</td>
			<td align="center">合同价格</td>
			<!--<td align="center">变更费用</td>-->
			<td align="center">审核</td>
			<td align="center">验收</td>
			<td align="center">安检</td>
			
			<td align="center">分包单位名称</td>
			<td align="center">合同价格</td>
			<!--<td align="center">变更费用</td>-->
			<td align="center">环评审查批复</td>
			<td align="center">验收批复</td>
			<td align="center">登记表</td>
			<td align="center">排污许可证</td>
			
			<td align="center">分包单位名称</td>
			<td align="center">合同价格</td>
			<!--<td align="center">变更费用</td>-->
			<td align="center">行政许可证</td>
			<td align="center">食品经营许可证</td>
			
			<td align="center">审核</td>
			<td align="center">验收</td>
			<td align="center">安检</td>
			<td align="center">供货证明文件</td>
			<td align="center">食品经营许可证</td>
			<td align="center">登记表</td>
			<td align="center">排污许可证</td>
			<td align="center">行政许可证</td>
			
			<!--<td align="center">备注</td>-->
		</tr>
		<%
			String sql = "select a.xmbh ,a.xmmc ,a.scqy,b.dec51,b.dec56,b.dec60,b.dec65,b.dec68,b.dec72,b.dec44,b.dec46,c.xfsj,c.xfys,c.xfan,c.ghzm,c.wcsj6,c.ghzm,c.pwxk,c.zpxk"; 
			sql += " from formtable_main_42 a left join formtable_main_51 b on a.xmbh=b.xmbh left join formtable_main_59 c on a.xmbh=c.xmbh";
			
			if(!fromDate.equals("") && !toDate.equals("")){
				sql += " where a.sqrq between '"+fromDate+"' and '"+toDate+"'";
			}else if(!fromDate.equals("")){
				sql += " where a.sqrq='"+fromDate+"'";
			}else if(!toDate.equals("")){
				sql += " where a.sqrq='"+toDate+"'";
			}
			
			if(!fromDate.equals("") || !toDate.equals("")){
				if(!XMNo.equals("")){
					sql += " and a.xmbh like '%"+XMNo+"%'";
				}
			}else{
				if(!XMNo.equals("")){
					sql += " where a.xmbh like '%"+XMNo+"%'";
				}
			}
			
			sql += " order by a.xmbh";
			rs.executeSql(sql);
			int a = 0;
			while(rs.next()){
				out.print("<tr>");
				//项目基本信息
				a = a+1;
				out.print("<td align='center'>"+a+"</td>");
				String xmbh = strUtil.vString(rs.getString("xmbh"));
				out.print("<td align='center'>"+xmbh+"</td>");//项目编号
				out.print("<td align='center'>"+rs.getString("xmmc")+"</td>");//项目名称
				
				String scqy = "";
				String xmqy = strUtil.vString(rs.getString("scqy"));
				if(!xmqy.equals("")){
					String qySql = "select selectname from workflow_selectitem where fieldid='9697' and selectvalue='"+xmqy+"'";
					rs1.executeSql(qySql);
					if(rs1.next()){
						scqy = strUtil.vString(rs1.getString("selectname"));
					}
				}
				out.print("<td align='center'>"+scqy+"</td>");//项目区域
				
				
				String xfhtyf = "";//分包单位名称-消防
				String xfhtje = "";//合同价格-消防
				String hbhtyf = "";//分包单位名称-环保
				String hbhtje = "";//合同价格-环保
				String zphtyf = "";//分包单位名称-招牌
				String zphtje = "";//合同价格-招牌
				
				String htSql = "select a.xmbh,a.fbqk,b.gys,a.htje from formtable_main_70 a left join uf_gys b on a.htyf=b.id where a.xmbh='"+xmbh+"'";
				rs1.executeSql(htSql);
				while(rs1.next()){
					String fbqk = strUtil.vString(rs1.getString("fbqk"));//分包情况
					if(fbqk.equals("0")){//消防
						xfhtyf = strUtil.vString(rs1.getString("gys"));
						xfhtje = strUtil.vString(rs1.getString("htje"));
					}else if(fbqk.equals("1")){//环保
						hbhtyf = strUtil.vString(rs1.getString("gys"));
						hbhtje = strUtil.vString(rs1.getString("htje"));
					}else if(fbqk.equals("2")){//招牌
						zphtyf = strUtil.vString(rs1.getString("htyf"));
						zphtje = strUtil.vString(rs1.getString("htje"));
					}
				}
				
				//消防
				out.print("<td align='center'>"+xfhtyf+"</td>");//分包单位名称
				out.print("<td align='center'>"+xfhtje+"</td>");//合同价格
				//out.print("<td align='center'></td>");//变更费用
				out.print("<td align='center'>"+rs.getString("dec51")+"</td>");//审核
				out.print("<td align='center'>"+rs.getString("dec56")+"</td>");//验收
				out.print("<td align='center'>"+rs.getString("dec60")+"</td>");//安检
				//环保
				out.print("<td align='center'>"+hbhtyf+"</td>");//分包单位名称
				out.print("<td align='center'>"+hbhtje+"</td>");//合同价格
				//out.print("<td align='center'></td>");//变更费用
				out.print("<td align='center'>"+rs.getString("dec65")+"</td>");//环评审查批复
				out.print("<td align='center'>"+rs.getString("dec68")+"</td>");//验收批复
				out.print("<td align='center'></td>");//登记表
				out.print("<td align='center'>"+rs.getString("dec72")+"</td>");//排污许可证
				//招牌
				out.print("<td align='center'>"+zphtyf+"</td>");//分包单位名称
				out.print("<td aalign='center'>"+zphtje+"</td>");//合同价格
				//out.print("<td align='center'></td>");//变更费用
				out.print("<td align='center'>"+rs.getString("dec44")+"</td>");//行政许可证
				//卫生
				out.print("<td align='center'>"+rs.getString("dec46")+"</td>");//食品经营许可证
				//竣工资料上传
				out.print("<td align='center'>"+rs.getString("xfsj")+"</td>");//审核
				out.print("<td align='center'>"+rs.getString("xfys")+"</td>");//验收
				out.print("<td align='center'>"+rs.getString("xfan")+"</td>");//安检
				out.print("<td align='center'>"+rs.getString("ghzm")+"</td>");//供货证明文件
				out.print("<td align='center'>"+rs.getString("wcsj6")+"</td>");//食品经营许可证
				out.print("<td align='center'>"+rs.getString("ghzm")+"</td>");//登记表
				out.print("<td align='center'"+rs.getString("pwxk")+"</td>");//排污许可证
				out.print("<td align='center'>"+rs.getString("zpxkd")+"</td>");//行政许可证
				//out.print("<td align='center'></td>");//备注
				out.print("</tr>");
			}	
		%>
		<tr>
			<td colspan="27" align="right" ><%=SystemEnv.getHtmlLabelName(20087,user.getLanguage())+"："+currentDate%></td>
		</tr>
	</tbody>
</table>
<%
	}
%>